# 导入 CCXT 库
import ccxt

# 创建交易所实例（以币安为例）
exchange = ccxt.binance({
    'apiKey': '你的API Key',  # 替换为你的 API Key
    'secret': '你的API Secret',  # 替换为你的 API Secret
})

# 加载市场数据
exchange.load_markets()

# 获取 BTC/USDT 的交易对信息
symbol = 'BTC/USDT'
ticker = exchange.fetch_ticker(symbol)
print(f"{symbol} 的最新价格: {ticker['last']}")

# 获取 BTC/USDT 的订单簿
orderbook = exchange.fetch_order_book(symbol)
print(f"{symbol} 的买一价: {orderbook['bids'][0][0]}, 卖一价: {orderbook['asks'][0][0]}")

# 获取账户余额
balance = exchange.fetch_balance()
print("账户余额:")
for currency, amount in balance['total'].items():
    if amount > 0:
        print(f"{currency}: {amount}")

# 下单（以限价单为例）
try:
    order = exchange.create_limit_buy_order(symbol, 0.001, 30000)  # 买入 0.001 BTC，价格 30000 USDT
    print("下单成功:", order)
except Exception as e:
    print("下单失败:", str(e))